import json
import os.path


def load_key(keyname: str) -> str:
    file_name = "Keys.json"
    if os.path.exists(file_name):
        with open(file_name, 'r') as file:
            keys = json.load(file)
        if keyname in keys and keys[keyname]:
            return keys[keyname]
        else:
            keyval = input("配置文件中没有相应key，请输入key值: ").strip()
            keys[keyname] = keyval
            with open(file_name, 'w') as file:
                json.dump(keys, file, indent=4)
            return keyval
    else:
        keyval = input("配置文件中没有相应key，请输入key值: ").strip()
        keys = {keyname: keyval}
        with open(file_name, 'w') as file:
            json.dump(keys, file, indent=4)
        return keyval


if __name__ == '__main__':
    print(load_key("siliconflow_api_key"))
